<template>
  <div mode="selector" @click="jumpToCommment">
    <div class="form-item">
      <div class="label">
        {{ label }}
      </div>
      <div class="content">
        <div v-if="commName == ''" class="placeholder">
          {{ placeholder }}
        </div>
        <div v-else>
          {{ commName }}
        </div>
        <arrow-right />
      </div>
    </div>
  </div>
</template>

<script>
import ArrowRight from '@/components/ze-oa-form/cpns/arrow-right.vue'

export default {
  name: 'ZePicker',
  components: { ArrowRight },
  props: {
    label: { type: String, default: '' },
    placeholder: { type: String, default: '请选择' },
    options: { type: Array, default: () => [] },
    labelKey: { type: String, default: 'label' },
    valueKey: { type: String, default: 'value' },
    value: {},
  },
  data() {
    return {
      selectedItem: null,
      commName: '',
      commId: '',
    }
  },
  mounted() {
    this.getData()
    uni.$on('edit2', (editdata) => {
      this.getData()
    })
    uni.$on('commPageChange', (data) => {
      this.commId = data.commId
      this.commName = data.commName
    })
  },
  methods: {
    getData() {
      try {
        const value = uni.getStorageSync('storage_comm')
        if (value) {
          this.commId = value.commId
          this.commName = value.commName
        }
      } catch (e) {
        // error
      }
    },
    jumpToCommment() {
      uni.navigateTo({
        url: `/pages/office/project-approval/approval-form/comm-list?commId=${this.commId}&commName=${this.commName}`,
      })
    },
    handleChange(e) {
      this.selectedItem = this.options[e.detail.value]
      this.$emit('input', this.selectedItem[this.valueKey])
    },
  },
}
</script>

<style lang="scss" scoped>
.form-item {
  font-size: 14px;
  font-weight: 400;
  line-height: 14px;
  padding: 15px 16px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f2f2f2;
  .label {
    color: #333333;
    // font-size: 14px;
  }

  .content {
    display: flex;
    align-items: center;
    column-gap: 5px;
  }

  .placeholder {
    color: #999999;
  }
}
</style>
